//
//  ViewController.m
//  YYKit-Study
//
//  Created by dev on 16/12/26.
//  Copyright © 2016年 zsw. All rights reserved.
//

#import "ViewController.h"
#import "YYTextStudyController.h"



@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *titles;
@property (nonatomic, strong) NSMutableArray *classNames;
@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTableView];
    
    self.titles = @[].mutableCopy;
    self.classNames = @[].mutableCopy;
    
    [self addCell:@"YYText" class:@"YYTextStudyController"];
    
    [self addCell:@"Weibo Demo" class:@"WBStatusTimelineViewController"];
    
}

- (void)addCell:(NSString *)title class:(NSString *)className {
    [self.titles addObject:title];
    [self.classNames addObject:className];
}

#pragma mark - Initialization

- (void)initTableView {
//    YYTableView *tableView = [[YYTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    YYTableView *tableView = [YYTableView new];
    tableView.frame = self.view.bounds;
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    
}


#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _titles.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"cellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (nil == cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    cell.textLabel.text = _titles[indexPath.row];
    
    return cell;
}

#pragma mark - <UITableViewDelegate Delegate>

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSString *className = _classNames[indexPath.row];
    
    Class class = NSClassFromString(className);
    
    if (class) {
        UIViewController *ctrl = class.new;
        ctrl.title = _titles[indexPath.row];
        [self.navigationController pushViewController:ctrl animated:YES];
    }
    
}



@end
